﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using IHISCETeim.BLL;
using IHISCETeim.Library;
using IHISCETeim.Model;
using System.Data;
using System.Text;

namespace IHISCETeim.Web.MachineSys.MacModel
{
    public partial class OCompleteMacNGReport :PageBase
    {

        protected override Permission[] PowerKey
        {
            get
            {
                return new Permission[] { Permission.查看 };
            }
        }
        protected override string DWZRef
        {
            get
            {
                return "OCompleteMacNGReport";
            }
        }

        protected int Year
        {
            get
            {
                return GetRequestValue<int>("year", DateTime.Now.Year);
            }
        }
        protected int Month
        {
            get
            {
                return GetRequestValue<int>("Month", DateTime.Now.Month);
            }
        }
        #region
        ///// <summary>
        ///// 当前要显示的问题分析月份 格式为2011-07
        ///// </summary>
        //protected string CurrShowMonth
        //{
        //    get
        //    {
        //        return Year.ToString() + "-" + Month.ToString();
        //    }
        //}

        ///// <summary>
        ///// 报表要开始显示的月份,上半年还是下半年
        ///// </summary>
        //protected int StateMonth {
        //    get
        //    {
        //        if (Month <= 6)
        //            return 1;
        //        else
        //            return 7;
        //    }
        //}
        ///// <summary>
        ///// 报表要结速显示的月份,上半年还是下半年
        ///// </summary>
        //protected int EndMonth
        //{
        //    get
        //    {
        //        return StateMonth + 5;
        //    }
        //}



        protected string GetYearList()
        {
            string liTemplete = "<option value='{0}' {1}>{0}年</option>";
            string rHtml = "";
            int nowYear = DateTime.Now.Year;
            for (int i = (nowYear - 3); i <= nowYear; i++)
            {
                rHtml = rHtml + string.Format(liTemplete, i, i == Year ? "selected" : "");
            }
            return rHtml;
        }

        //#region 相关方法
        ///// <summary>
        ///// 获取报表1相关数据
        ///// </summary>
        ///// <param name="tYear"></param>
        ///// <param name="tMoneth"></param>
        ///// <returns>
        ///// 只返回一行
        ///// 列AllCount表示所有的性能检测台数
        ///// 列NGCount表示有出现问题记录的台数
        ///// 列NotNGCount表示未出现问题的台数
        ///// 列FPY表示合格率(NotNGCount/AllCount)
        ///// </returns>
        //protected DataRow OInspection_GetReport1(object tYear,object tMoneth)
        //{
        //    DateTime statedate = Convert.ToDateTime( tYear.ToString() + "-" + tMoneth.ToString() + "-01 00:00:00");
        //    DateTime enddate = Convert.ToDateTime(statedate.AddMonths(1).AddDays(-1).ToString("yyyy-MM-dd 23:59:59"));

        //    return OInspectionController.OInspection_GetReport1(statedate, enddate).Rows[0];
        //}
        ///// <summary>
        ///// 获取报表2相关数据
        ///// </summary>
        ///// <param name="tYear"></param>
        ///// <param name="tMoneth"></param>
        ///// <returns>
        ///// 只返回一行
        ///// 列AllCount表示所有的出入库检查台数
        ///// 列NGCount表示有出现问题记录的台数
        ///// 列NotNGCount表示未出现问题的台数
        ///// 列FPY表示合格率(NotNGCount/AllCount)
        ///// </returns>
        //protected DataRow OInspection_GetReport2(object tYear, object tMoneth)
        //{
        //    DateTime statedate = Convert.ToDateTime(tYear.ToString() + "-" + tMoneth.ToString() + "-01 00:00:00");
        //    DateTime enddate = Convert.ToDateTime(statedate.AddMonths(1).AddDays(-1).ToString("yyyy-MM-dd 23:59:59"));

        //    return OInspectionController.OInspection_GetReport2(statedate, enddate).Rows[0];
        //}
        ///// <summary>
        ///// 获取指定时间段内机型
        ///// </summary>
        ///// <param name="tYear"></param>
        ///// <param name="tMoneth"></param>
        ///// <returns></returns>
        //protected List<string> GetReportMacType3(object tYear, object tMoneth)
        //{
        //    DateTime statedate = Convert.ToDateTime(tYear.ToString() + "-" + tMoneth.ToString() + "-01 00:00:00");
        //    DateTime enddate = Convert.ToDateTime(statedate.AddMonths(1).AddDays(-1).ToString("yyyy-MM-dd 23:59:59"));
        //    DataTable DT = OInspectionController.OInspection_GetReportMacType3(statedate, enddate);
        //    List<string> lisCol = new List<string>();
        //    foreach (DataRow dr in DT.Rows)
        //    {
        //        lisCol.Add(dr["MachineType"].ToString());
        //    }
        //    if (lisCol.Count <= 0)
        //    {
        //        lisCol.Add("55NSL");
        //        lisCol.Add("65NS");
        //        lisCol.Add("80NS");
        //    }
        //    return lisCol;
        //}
        ///// <summary>
        ///// 
        ///// </summary>
        ///// <param name="ItemType"></param>
        ///// <param name="colLabel">colLabel格式为 2011-07,55NSL</param>
        ///// <returns></returns>
        //protected object OInspection_GetReport3(string ItemType,string colLabel)
        //{
        //    string[] cols = colLabel.Split(new char[] { ',' });
        //    DateTime statedate = Convert.ToDateTime(cols[0] + "-01 00:00:00");
        //    DateTime enddate = Convert.ToDateTime(statedate.AddMonths(1).AddDays(-1).ToString("yyyy-MM-dd 23:59:59"));
        //    string macType = cols[1];
        //    return OInspectionController.OInspection_GetReport3(macType, ItemType, statedate, enddate);

        //}

        //protected DataTable OInspection_GetReport4(object tYear, object tMoneth)
        //{
        //    DateTime statedate = Convert.ToDateTime(tYear.ToString() + "-" + tMoneth.ToString() + "-01 00:00:00");
        //    DateTime enddate = Convert.ToDateTime(statedate.AddMonths(1).AddDays(-1).ToString("yyyy-MM-dd 23:59:59"));

        //    return OInspectionController.OInspection_GetReport4(statedate, enddate);
        //}

        //protected DataTable OInspection_GetReport5(object tYear, object tMoneth)
        //{
        //    DateTime statedate = Convert.ToDateTime(tYear.ToString() + "-" + tMoneth.ToString() + "-01 00:00:00");
        //    DateTime enddate = Convert.ToDateTime(statedate.AddMonths(1).AddDays(-1).ToString("yyyy-MM-dd 23:59:59"));

        //    return OInspectionController.OInspection_GetReport5(statedate, enddate);
        //}

        //protected DataTable OInspection_GetReport6(object tYear, object tMoneth)
        //{
        //    DateTime statedate = Convert.ToDateTime(tYear.ToString() + "-" + tMoneth.ToString() + "-01 00:00:00");
        //    DateTime enddate = Convert.ToDateTime(statedate.AddMonths(1).AddDays(-1).ToString("yyyy-MM-dd 23:59:59"));

        //    return OInspectionController.OInspection_GetReport6(statedate, enddate);
        //}
        //#endregion



        protected void Page_Load(object sender, EventArgs e)
        {
            this.AddLog(Permission.查看,Year.ToString()+Month.ToString());

        //    BindReport1Dat();
        //    BindReport2Dat();
        //    BindReport4();
        //    BindReport5();
        //    BindReport6();

        }
        ///// <summary>
        ///// 绑定性能检测合格
        ///// </summary>
        //protected void BindReport1Dat()
        //{ 
        //    DataTable dt = new DataTable();
        //    //dt.Columns.Add(string.Format("{0}年{1}月", Year, Month), typeof(string));
        //    for (int sindex = StateMonth; sindex <= EndMonth; sindex++)
        //    {
        //        dt.Columns.Add(string.Format("{0}年{1}月", Year, sindex), typeof(string));
        //    }

        //    DataRow dr = dt.NewRow();
        //    int rowIndex = 0;
        //    for (int sindex = StateMonth; sindex <= EndMonth; sindex++)
        //    {
        //        dr[rowIndex] =Convert.ToDecimal( OInspection_GetReport1(Year, sindex)["FPY"]).ToString("F1")+"%";
        //        rowIndex++;
        //    }
        //    dt.Rows.Add(dr);

        //    gvReport1.DataSource = dt;
        //    gvReport1.DataBind();
        //}
        ///// <summary>
        ///// 
        ///// </summary>
        //protected void BindReport2Dat()
        //{
        //    DataTable dt = new DataTable();
        //    //dt.Columns.Add(string.Format("{0}年{1}月", Year, Month), typeof(string));
        //    for (int sindex = StateMonth; sindex <= EndMonth; sindex++)
        //    {
        //        dt.Columns.Add(string.Format("{0}年{1}月", Year, sindex), typeof(string));
        //    }

        //    DataRow dr = dt.NewRow();
        //    int rowIndex = 0;
        //    for (int sindex = StateMonth; sindex <= EndMonth; sindex++)
        //    {
        //        dr[rowIndex] = Convert.ToDecimal(OInspection_GetReport2(Year, sindex)["FPY"]).ToString("F1") + "%";
        //        rowIndex++;
        //    }
        //    dt.Rows.Add(dr);

        //    gvReport2.DataSource = dt;
        //    gvReport2.DataBind();
        //}
        ///*
        //protected void BindReport3Dat()
        //{
        //    DataTable dt = new DataTable();
        //    dt.Columns.Add("机型", typeof(string));
        //    for (int sindex = StateMonth; sindex <= EndMonth; sindex++)
        //    {
        //        List<string> colNames= GetReportMacType3(Year, sindex);
        //        if (colNames.Count > 0)
        //        {
        //            colNames.Add("合计");                
        //        }
        //        foreach (string lab in colNames)
        //        {
        //            dt.Columns.Add(string.Format("{0}-{1},{2}", Year, sindex, lab), typeof(string));
        //        }
        //    }

        //    string[] items = new string[] { "性能检测台数", "性能检测品异台数", "性能检测不良率", "出入库检查台数", "出入库检查品异台数", "出入库不良率" };

        //    foreach (string itemtype in items)
        //    {
        //        DataRow dr = dt.NewRow();
        //      //  dr[0] = itemtype;
        //        foreach (DataColumn dc in dt.Columns)
        //        {
        //            if (dc.Caption == "机型")
        //                dr[0] = itemtype;
        //            else
        //            {
        //                object x = OInspection_GetReport3(itemtype, dc.ColumnName);
        //                if (itemtype == "性能检测不良率" || itemtype == "出入库不良率")
        //                    dr[dc.ColumnName] = Convert.ToDecimal(x).ToString("F2") + "%";
        //                else
        //                    dr[dc.ColumnName] = x;
        //            }
        //        }
        //        dt.Rows.Add(dr);
        //    }

        //   // DataRow dr = dt.NewRow();
        //    //dt.Rows.Add(dr);
        //    gvReport3.DataSource = dt;
        //    gvReport3.DataBind();
        //}
        //*/
        //protected string BindReport3Dat2()
        //{
        //    StringBuilder sb = new StringBuilder();
        //    sb.Append("<table class='list' width='2000px' style=\" text-align:center!important;\">");
        //    //表头添加
        //    sb.Append("<tr style='background-color:#99CCFF;'>");
        //    sb.AppendFormat("<th>{0}</th>", "项目&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;月份");
        //    for (int sindex = StateMonth; sindex <= EndMonth; sindex++)
        //    {
        //        List<string> colNames = GetReportMacType3(Year, sindex);
        //        if (colNames.Count > 0)
        //        {
        //            colNames.Add("合计");
        //            sb.AppendFormat("<th colspan='{1}'>{0}月</th>", sindex, colNames.Count);
        //        }                
        //    }
        //    sb.Append("</tr>");
        //    //表内容添加
        //    //1.机型行添加
        //    sb.Append("<tr>");
        //    sb.AppendFormat("<td>{0}</td>", "机型");
        //    for (int sindex = StateMonth; sindex <= EndMonth; sindex++)
        //    {
        //        List<string> colNames = GetReportMacType3(Year, sindex);
        //        if (colNames.Count > 0)
        //        {
        //            colNames.Add("合计");                    
        //        }
        //        foreach (string colLabel in colNames)
        //        {
        //            sb.AppendFormat("<td>{0}</td>", colLabel);
        //        }
        //    }
        //    sb.Append("</tr>");

        //    //2.具体内容添加
        //    string[] items = new string[] {"性能检测台数", "性能检测品异台数", "性能检测不良率", "出入库检查台数", "出入库检查品异台数", "出入库不良率" };
        //    foreach (string itemtype in items)
        //    {
        //        sb.Append("<tr>");
        //        sb.AppendFormat("<td>{0}</td>", itemtype);
        //        for (int sindex = StateMonth; sindex <= EndMonth; sindex++)
        //        {
        //            List<string> colNames = GetReportMacType3(Year, sindex);
        //            if (colNames.Count > 0)
        //            {
        //                colNames.Add("合计");
        //            }
        //            foreach (string colLabel in colNames)
        //            {
        //                object x = OInspection_GetReport3(itemtype, Year.ToString() + "-" + sindex.ToString() + "," + colLabel);
        //                object showx = 0;
        //                if (itemtype == "性能检测不良率" || itemtype == "出入库不良率")
        //                    showx = Convert.ToDecimal(x).ToString("F2") + "%";
        //                else
        //                    showx = x;

        //                sb.AppendFormat("<td>{0}</td>", showx);
        //            }
        //        }
        //        sb.Append("</tr>");
        //    }

        //    sb.Append("</table>");

        //    return sb.ToString();
        //}

        //protected void BindReport4()
        //{
        //    DataTable sDT = OInspection_GetReport4(Year, Month);
        //    DataTable NDT = new DataTable();
        //    NDT.Columns.Add("工位", typeof(string));
        //    foreach (DataRow sDR in sDT.Rows)
        //    {
        //        NDT.Columns.Add(sDR[0].ToString(), typeof(string));
        //    }

        //    DataRow NDR = NDT.NewRow();
        //    for (int rindex = 0; rindex < NDT.Columns.Count; rindex++)
        //    {
        //        if (rindex == 0)
        //            NDR[0] = "品异次数";
        //        else
        //            NDR[rindex] = sDT.Rows[rindex-1][1].ToString();
        //    }
        //    NDT.Rows.Add(NDR);
        //    this.gvReport4.DataSource = NDT;
        //    this.gvReport4.DataBind();
        //}


        //protected void BindReport5()
        //{
        //    this.gvReport5.DataSource = OInspection_GetReport5(Year,Month);
        //    this.gvReport5.DataBind();
        //}

        //protected void BindReport6()
        //{
        //    this.gvReport6.DataSource = OInspection_GetReport6(Year, Month);
        //    this.gvReport6.DataBind();
        //}
        #endregion
    }
}